﻿using System;
using System.Data;
using System.Data.OleDb;

using Joel.ImpresionesJL.AccesoDatos.Interfaces;

namespace Joel.ImpresionesJL.AccesoDatos
{
    public class ServicioDatosTelefono : ServicioDatosBase, IServicioDatosTelefono
    {
        #region Constructores

        public ServicioDatosTelefono()
        { }

        #endregion

        #region Metodos

        public DataSet ClientesTelefonos_DevolverPorId(Int32 idClienteTelefono)
        {
            try
            {
                OleDbCommand cm = new OleDbCommand("ClientesTelefonos_DevolverPorId", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OleDbParameter("@idClienteTelefono", idClienteTelefono));
                OleDbDataAdapter da = new OleDbDataAdapter(cm);
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public DataSet ClientesTelefonos_DevolverPorIdCliente(Int32 idCliente)
        {
            try
            {
                OleDbCommand cm = new OleDbCommand("ClientesTelefonos_DevolverPorIdCliente", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OleDbParameter("@idCliente", idCliente));
                OleDbDataAdapter da = new OleDbDataAdapter(cm);
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public Int32 ClientesTelefonos_Insertar(Int32 idCliente, Int32 idTipoTelefono, String numero)
        {
            try
            {
                OleDbCommand cm = new OleDbCommand("ClientesTelefonos_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OleDbParameter("@idCliente", idCliente));
                cm.Parameters.Add(new OleDbParameter("@idTipoTelefono", idTipoTelefono));
                cm.Parameters.Add(new OleDbParameter("@Numero", numero));
                cm.Connection.Open();
                return Convert.ToInt32(cm.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void ClientesTelefonos_Modificar(Int32 idClienteTelefono, Int32 idCliente, Int32 idTipoTelefono, String numero)
        {
            try
            {
                OleDbCommand cm = new OleDbCommand("ClientesTelefonos_Modificar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OleDbParameter("@idClienteTelefono", idClienteTelefono));
                cm.Parameters.Add(new OleDbParameter("@idCliente", idCliente));
                cm.Parameters.Add(new OleDbParameter("@idTipoTelefono", idTipoTelefono));
                cm.Parameters.Add(new OleDbParameter("@Numero", numero));
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void ClientesTelefonos_Eliminar(Int32 idClienteTelefono)
        {
            try
            {
                OleDbCommand cm = new OleDbCommand("ClientesTelefonos_Eliminar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OleDbParameter("@idClienteTelefono", idClienteTelefono));
                cm.Connection.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        #endregion
    }
}
